home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / 121_01.zip / DATE.C < prev    next >
Text File  |  1993-06-01  |  2KB  |  77 lines

  1. /*
  2. HEADER: CUG 121.??;
  3.  
  4.     TITLE:    Date - display date from Computime board;
  5.     VERSION:    1.0;
  6.     DATE:    09/01/85;
  7.     DESCRIPTION: "This program extracts the date & time from the Computime
  8.         clock/calendar board and displays it on the console.";
  9.     KEYWORDS:    computime, date, time;
  10.     SYSTEM:    CP/M;
  11.     FILENAME:    DATE.C;
  12.     WARNINGS:    "Requires Computime clock/calendar board.";
  13.     SEE-ALSO:    DATE.H (header file), DATEUP.C (update clock/calendar);
  14.     AUTHORS:    Mike W. Meyer;
  15.     COMPILERS:    BDS-C 1.50;
  16. */
  17.  
  18. #include <bdscio.h>
  19. #include "date.h"
  20.  
  21. char *days[7], *months[12] ;
  22.  
  23. main() {
  24.     struct time tick ;
  25.     struct date tock ;
  26.  
  27.     months[0] = "Jan"; months[1] = "Feb"; months[2] = "Mar" ;
  28.     months[3] = "Apr"; months[4] = "May"; months[5] = "Jun" ;
  29.     months[6] = "Jul"; months[7] = "Aug"; months[8] = "Sep" ;
  30.     months[9] = "Oct"; months[10] = "Nov"; months[11] = "Dec" ;
  31.     days[0] = "Sun"; days[1] = "Mon"; days[2] = "Tue"; days[3] = "Wed" ;
  32.     days[4] = "Thu"; days[5] = "Fri"; days[6] = "Sat" ;
  33.     for (;; sleep(5)) {
  34.         gettime(&tick) ;
  35.         getdate(&tock) ;
  36.         printf("%s %s %2d %2d:%02d:%02d CST 19%02d\n",
  37.             days[tock . weekday], months[tock . month],
  38.             tock . day, tick . hours, tick . minutes,
  39.             tick . seconds, tock . year) ;
  40.         }
  41.     }
  42.  
  43. gettime(now) struct time *now; {
  44.     char i, time[6] ;
  45.  
  46.     outp(CLDATA, CLHOLD) ;
  47.     for (i = 0; i < 6; i++)
  48.         time[i] = getclock(i) ;
  49.     outp(CLDATA, CLREL) ;
  50.     now -> seconds = time[0] + 10 * time[1] ;
  51.     now -> minutes = time[2] + 10 * time[3] ;
  52.     now -> hours = time[4] + 10 * ((i = time[5]) & CLOMASK) ;
  53.     /* if we are in AM/PM mode, & it's PM, fix it */
  54.     if (!(i & CL24HR) && (i & CLAMPM)) now -> hours += 12 ;
  55.     }
  56.  
  57. getdate(now) struct date *now; {
  58.     char i, time[7] ;
  59.  
  60.     outp(CLDATA, CLHOLD) ;
  61.     for (i = 0; i < 7; i++)
  62.         time[i] = getclock(i + 6) ;
  63.     outp(CLDATA, CLREL) ;
  64.     now -> day = time[1] + 10 * (time[2] & CLOMASK) ;
  65.     now -> month = time[3] + 10 * time[4] - 1 ;
  66.     now -> year = time[5] + 10 * time[6] ;
  67.     now -> weekday = *time ;
  68.     }
  69.  
  70. char getclock(reg) char *reg; {
  71.     char x ;
  72.  
  73.     outp(CLADDR, reg + CLOFF) ;
  74.     x = inp(CLADDR) & CLMASK ;
  75.     return x ;
  76.     }
  77.